"-------Shortcuts for the plugin ctrlp let g:ctrlp_map = '<c-p>' let g:ctrlp_cmd = 'CtrlP' let g:ctrlp_by_filename=1 "set the types of files that can be ignored let g:ctrlp_custom_ignore = { \ 'dir': '\v[\/]\.(git|hg|svn|rvm)$', \ 'file': '\v\.(exe|so|dll|zip|tar|tar.gz|pyc)$', \ }
"-------Settings for NERDTree-------- autocmd StdinReadPre * let s:std_in=1 autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif autocmd vimenter * NERDTree "Close vim when the NERDTree is the only window autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif let NERDTreeIgnore=['\.pyc','\~$','\.swp'] let g:NERDTreeShowLineNumbers=1
" NERDTress File highlighting "Set the vim-devicons
"Can be enabled or disabled "vim-nerdtree-syntax-highlight settings """""""""""""""""""""""""""""" let g:WebDevIconsDisableDefaultFolderSymbolColorFromNERDTreeDir = 1 let g:WebDevIconsDisableDefaultFileSymbolColorFromNERDTreeFile = 1 " not to show brackets around flags let g:webdevicons_conceal_nerdtree_brackets = 1 " enable folder/directory glyph flag (disabled by default with 0) let g:WebDevIconsUnicodeDecorateFolderNodes = 1 " enable open and close folder/directory glyph flags (disabled by default with 0) let g:DevIconsEnableFoldersOpenClose = 1
" use double-width(1) or single-width(0) glyphs " only manipulates padding, has no effect on terminal or set(guifont) font let g:WebDevIconsUnicodeGlyphDoubleWidth = 0 " Force extra padding in NERDTree so that the filetype icons line up vertically let g:WebDevIconsNerdTreeGitPluginForceVAlign = 1
"Highlight full name (not only icons). You need to add this if you don't have vim-devicons and want highlight. let g:NERDTreeFileExtensionHighlightFullName = 1 let g:NERDTreeExactMatchHighlightFullName = 1 let g:NERDTreePatternMatchHighlightFullName = 1
"Highlight full name (not only icons). You need to add this if you don't have vim-devicons and want highlight. let g:NERDTreeHighlightFolders = 1
"highlights the folder name let g:NERDTreeHighlightFoldersFullName = 1
"you can add these colors to your .vimrc to help customizing let s:brown = "905532" let s:aqua = "3AFFDB" let s:blue = "689FB6" let s:darkBlue = "44788E" let s:purple = "834F79" let s:lightPurple = "834F79" let s:red = "AE403F" let s:beige = "F5C06F" let s:yellow = "F09F17" let s:orange = "D4843E" let s:darkOrange = "F16529" let s:pink = "CB6F6F" let s:salmon = "EE6E73" let s:green = "8FAA54" let s:Turquoise = "40E0D0" let s:lightGreen = "31B53E" let s:white = "FFFFFF" let s:rspec_red = "FE405F" let s:git_orange = "F54D27" let s:gray = "808A87"
let g:NERDTreeExtensionHighlightColor = {} " this line is needed to avoid error let g:NERDTreeExtensionHighlightColor['py'] = s:orange " sets the color of py files to blue let g:NERDTreeExtensionHighlightColor['tex'] = s:yellow " sets the color of tex files to blue let g:NERDTreeExtensionHighlightColor['c'] = s:green " sets the color of c files to blue let g:NERDTreeExtensionHighlightColor['pdf'] = s:beige " sets the color of pdf files to blue let g:NERDTreeExtensionHighlightColor['c++'] = s:green " sets the color of c++ files to blue
"-------settings for the plugin asyncrun "open quickfix windown, the height is 6 let g:asyncrun_open =6 "The bell rings when the task is finished let g:asyncrun_bell =1 let g:asyncrun_rootmarks = ['.svn', '.git', '.root', '_darcs', 'build.xml'] "call for the quickfix window autocmd FileType c,cpp nnoremap <leader>c :call asyncrun#quickfix_toggle(6)<cr> "Shortcuts for compiling and run the c file autocmd FileType c,cpp nnoremap <silent> <leader>b :AsyncRun -cwd=<root> make <cr> autocmd FileType c,cpp nnoremap <silent> <leader>r :AsyncRun -cwd=<root> -raw make run <cr>
从上面可以看出,使用Vim来开发大型项目(源文件很多)是不太方便,使用集成开发环境VS或者VS code是一个相对更好的选择。Vim更适合来编写单个文件,比如我经常来写论文的.tex文件。当然,在写论文时,我们也可以将不同部分(比如 abstract, introduction, system model等等)分成不同的.tex文件,然后在主文件中使用\input命令直接调用即可,这里就没有这里的C/C++项目复杂,不要自己编写makefile。另外需要注意的是,我也是设置<leader>b编译.tex文件。在编译C项目后,在同一vim窗口不同tab再编译.tex文件会产生错误。这里我们可以用一个新的vim窗口打开.tex文件编译即可。
目录导航
在写较长的文章或则程序时,我们可以借助这里的目录导航快速跳转到想到的地方去。安装该插件的代码如下:
1
Plugin 'majutsushi/tagbar'
其常用设置如下:
1 2 3 4 5 6 7 8
"-------Configurations for the plugin ctags let g:tagbar_ctags_bin='/usr/local/bin/ctags' let g:tagbar_width=30 let g:tagbar_right=1 "AutoOpen tagbar for c/c++ files autocmd BufReadPost *.cpp,*.c,*.h,*.hpp,*.cc call tagbar#autoopen() "Open or close tagbar map <leader>tb :TagbarToggle<CR>
"-------Configurations for Python set encoding=utf-8 au BufNewFile,BufRead *.py set tabstop=4 |set softtabstop=4|set shiftwidth=4|set textwidth=79|set expandtab|set autoindent|set fileformat=unix set clipboard=unnamed let python_highlight_all=1
function CheckPythonSyntax() let mp = &makeprg let ef = &errorformat let exeFile = expand("%:t") setlocal makeprg=python3\ -u set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m silent make % copen let &makeprg = mp let &errorformat = ef endfunction au filetype python map <leader>b :w <cr> :call CheckPythonSyntax() <cr> :cw<cr>